---------------------------------------------------------------
-- @Copyright：           zour
-- @Description：         LuaConfig配置文件读取校验接口，广告服目前没有使用，暂留
-- @modify time           2021-10-14
---------------------------------------------------------------
require "modules.business_advert.advert_define"
local ns_luaConfigMgr = require("modules.center_server.luaConfigProxy")

local ns_config_get = {}

--=================================== config get =====================================
ns_config_get.init = function()
    ns_luaConfigMgr.register_config_file_change('business_advert_config', 60, ns_config_get.handle_advert_config, "business_advert")
    ns_luaConfigMgr.register_config_file_change('ma_config', 60, ns_config_get.handle_ma_config, "business_advert")
end

ns_config_get.handle_advert_config = function (content_)
    --log.error(content_)  --打印在 error_business_advert.log里
    --log.day_list(ADVERT,content_)
    local function onload()
        assert(content_)
        local config_ = uu.safe_loadstring(content_)
        ns_config.business_advert_config = config_
    end
    
    xpcall(onload, function (errmsg)
        log.day_list(ADVERT, "error::handle_business_advert_config xpcall failed ,errmsg:" .. errmsg )
        log.error( debug.traceback() )
    end)
end

ns_config_get.handle_ma_config = function (content_)
    --log.error(content_)  --打印在 error_business_advert.log里
    --log.day_list(ADVERT,content_)
    local function onload()
        assert(content_)
        local config_ = uu.safe_loadstring(content_)
        ns_config.ma_config = config_
    end
    
    xpcall(onload, function (errmsg)
        log.day_list(ADVERT, "error::handle_ma_config xpcall failed ,errmsg:" .. errmsg )
        log.error( debug.traceback() )
    end)
end


--=================================== config check =====================================
-- 最小版本限制
ns_config_get.version_min_check = function(minVer, ver)
    if uu.ver2i(ver) < uu.ver2i(minVer) then
        return false
    end

    return true
end

--最大版本限制
ns_config_get.version_max_check = function(maxVer, ver)
    if uu.ver2i(maxVer) < uu.ver2i(ver) then
        return false
    end
    return true
end

-- 渠道白名单
ns_config_get.apiid_check = function(apiids, apiid)
    for id in apiids:gmatch("(%d+)") do
        if tonumber(id) ==  tonumber(apiid) then
            return true
        end
    end
    return false
end

--渠道黑名单
ns_config_get.apiid_no_check = function(apiids_no, apiid)
    for id in apiids_no:gmatch("(%d+)") do
        if tonumber(id) ==  tonumber(apiid) then
            return false
        end
    end
    return true
end

return ns_config_get